﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Studio77.PopBall.Util;
using System.Windows.Media.Imaging;
using Studio77.PopBall.Core;

namespace Studio77.PopBall.Views
{
    public partial class ScoreView : UserControl
    {
        List<Image> imgs = new List<Image>();

        public ScoreView()
        {
            InitializeComponent();
            this.StoryboardShow.Completed += StoryboardShow_Completed;
            imgs.Add(imgCommentAmazing);
            imgs.Add(imgCommentExecllent);
            imgs.Add(imgCommentGood);
            imgs.Add(imgCommentGreat);
            imgs.Add(imgCommentNice);
            imgs.Add(imgCommentUnbelievable);
        }

        internal void Hide()
        {
            this.StoryboardResume.Begin();
            this.Visibility = System.Windows.Visibility.Collapsed;

        }

        internal void Show(int score, EliminateComment comment)
        {
            this.Visibility = System.Windows.Visibility.Visible;
            this.txtScore.Text = "+" + score;

            if (comment == EliminateComment.None)
            {
                foreach (var item in imgs)
                {
                    item.Visibility = System.Windows.Visibility.Collapsed;
                }
            }
            else
            {
                foreach (var item in imgs)
                {
                    item.Visibility = System.Windows.Visibility.Collapsed;
                }
                int index = -1;
                bool isGreatScore = false;
                switch (comment)
                {
                    case EliminateComment.Amazing:
                        index = 0;
                        isGreatScore = true;
                        break;
                    case EliminateComment.Excellent:
                        index = 1;
                        isGreatScore = true;
                        break;
                    case EliminateComment.Good:
                        index = 2;
                        break;
                    case EliminateComment.Great:
                        index = 3;
                        break;
                    case EliminateComment.Nice:
                        index = 4;
                        break;
                    case EliminateComment.Unbelievably:
                        index = 5;
                        isGreatScore = true;
                        break;
                }
                if (index >= 0 && index < imgs.Count)
                {
                    imgs[index].Visibility = System.Windows.Visibility.Visible;
                }
                if (isGreatScore)
                {
                    //播放非凡消除音效
                    SoundManager.PlayEffect(SoundManager.highScore);
                }
            }

            this.StoryboardShow.BeginTime = TimeSpan.FromMilliseconds(30);
            this.StoryboardShow.Begin();
        }

        void StoryboardShow_Completed(object sender, EventArgs e)
        {
            Hide();
        }
    }
}
